<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');
/**
 * 我的收藏
 * */
class Deliver_model extends MY_Model
{
    private $table = 'deliver';
	public function __construct()
	{
		parent::__construct($this->table);
	
	}

	/**
	 * 添加
	 * */
	public function insertData( $userData )
	{
	    $bool = $this->db->insert($this->table, $userData);
	    $res = $bool ? $this->db->insert_id() : false;
	    return $res;
	}
	
	
	
	/**
	 * 获取投递的职位
	 * */
	public function getByUserId($userId=0,$limit,$offset){
	    $select='job.jobId,type.typeName as jobName,concat("'.IMAGEHOST.'",job.logo) as logo,exp.typeName as expName,
                 salary.typeName as salaryName,cityName,company.name as companyName,job.createTime';
	    $this->db->select($select);
	    $this->db->where('deliver.userId',$userId);
	    
	    $this->db->join('job','job.jobId=deliver.jobId');
	    $this->db->join('type','type.typeId=job.typeId','left');        //职位ID
	    $this->db->join('type as exp','exp.typeId=job.expId','left');        //经验分类ID
	    $this->db->join('type as salary','salary.typeId=job.salaryId','left');        //薪资分类ID
	    
	    
	    $this->db->join('company','company.companyId=job.companyId');        //职位
	    $this->db->join('city','city.cityId=company.cityId','left');        //城市ID
	    $this->db->group_by('job.jobId');
	    
	    $this->db->order_by('deliver.createTime','desc');
	    $res=$this->db->get($this->table,$limit,$offset)->result_array();
	    return $res;
	}
	
	
	public function getUserdeliverionCount( $typeFlag='' ,$userId=0 )
	{
	    $this->db->where('c.userId' ,$userId);
	    if(isset($typeFlag))
	    {
	        $this->db->where('c.typeFlag' ,$typeFlag);
	    }	
	    $this->db->where('d.issue',1); //发布
	    $this->db->where('d.examinestatus',1);//通过审核
	    $this->db->where('d.status',0);//状态
	    $this->db->where('d.deleteFlag',0);//是否状态
	    $this->db->join('dzlist as d','d.listId=c.listId','left');
	    return $this->db->count_all_results( $this->table .' as c');
	}
	
	/**
	 * 删除
	 * */
	
	public function delete($where)
	{
	    $this->db->where($where)->delete($this->table);
	    return $this->db->affected_rows();
	}
	
	/**
	 *获取单条数据
	 * */
	public function getUserdeliverionRow($jobId,$companyId,$userId)
	{
	    $this->db->where('jobId', $jobId);
	    $this->db->where('companyId', $companyId);
	    $this->db->where('userId', $userId);
	    $result = $this->db->get($this->table);
	    return $result->row_array();
	}
}
?>